<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/common/header.jsp"%>

<script type="text/javascript">

Ext.onReady(function() {
    Ext.QuickTips.init();
  
    var form = new Ext.form.FormPanel({
        border: false,
        bodyStyle: 'padding:15px',
        defaultType: 'textfield',
        width: 350,
        frame: true,
        defaults: {
            width: 200,
            msgTarget: 'side'
        },
        items: [{
            fieldLabel: '账户名称',
            name: 'loginId',
            allowBlank: false
        },{
            fieldLabel: '密码',
            name: 'password',
            inputType: 'password'
        }]
    });
    
    var action = new Ext.Action({
        text: '登录',
        handler: function(){
            if(form.getForm().isValid()){
                        form.getForm().submit({
                            url: 'login.do',
//                          waitTitle: '请等待',
                            waitMsg: '正在登录...',
//                          waitMsgTarget: true,
                            timeout: 5,
                            success: function(form, action){
                                this.document.location.href='<c:url value="/common/main.html" />';
                            },
                            failure: function(form, action){
                                if (action.failureType === Ext.form.Action.CONNECT_FAILURE) {
                                    //Ext.MessageBox.alert('连接出错',
                                    //    'Status:'+action.response.status+': '+
                                    //    action.response.statusText);
                                    Ext.MessageBox.alert('登录出错', '用户名或密码有错！');
                                }
                                if (action.failureType === Ext.form.Action.SERVER_INVALID){
                                    // server responded with success = false
                                    var emsg = action.result.errorMessage;
                                    if (emsg && emsg !== '') {
                                        Ext.MessageBox.alert('出错', emsg);
                                    }
                                }
                                Ext.MessageBox.alert('出错', action.result.errors.loginId);
                            }
                        });
                    }
        }
    });
    
    var window = new Ext.Window({
        title: '重庆邮电大学统一认证及授权平台 登录',
        width: 400,
        height: 200,
        minWidth: 300,
        minHeight: 200,
        layout: 'fit',
        plain:true,
        bodyStyle:'padding:5px;',
        buttonAlign:'center',
        closable:false,
        items: form,
        buttons: [action]
    });

    window.show();
});

</script>
<%@ include file="/WEB-INF/views/common/footer.jsp"%>